<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%@ include file="/v2/console/common/taglibs.jsp"%>
<!DOCTYPE HTML>
<html>
<head>
	<link rel="stylesheet" href="${path}/v2/console/css/base.css">
	<link rel="stylesheet" href="${path}/v2/console/css/style.css">
	<script src="${path}/v2/console/js/jquery-1.9.1.min.js"></script>
	<%-- <script src="${path}/v2/console/js/globle.js"></script> --%>
	<%-- <script src="${path}/v2/console/My97DatePicker/WdatePicker.js"></script> --%>
	<script>
	</script>
</head>
<body>
<div id="wrapper">
	<div class="main">
		<div class="main-right">
			<div class="column-name">
				<h2>
					内容管理 > <b>文章列表</b>
				</h2>
			</div>
			<form id="pageForm" name="form"
				action="${pageContext.request.contextPath}/siteArticle/siteArticleList.html"
				method="post">
				<input type="hidden" name="nodeId" value="${nodeId}"/>
				<div class="main-top">
					<div class="fl">
						<a href="${pageContext.request.contextPath}/siteArticle/toAddArticle.html?nodeId=${nodeId}"
								class="btn btn-p">写文章</a>
						<a href="javascript:void(0);" class="btn btn-p" id="pub">发布</a>
						<!-- <a href="javascript:void(0);" class="btn btn-p" id="nopub">待发布</a> -->
						<%-- <a href="${pageContext.request.contextPath}/siteArticle/toFirstAdd.html?nodeId=${nodeId}"
								class="btn btn-p">增加模块首页内容</a> --%>
						<%-- <a href="${pageContext.request.contextPath}/siteArticle/toFirstEdit.html?nodeId=${nodeId}"
								class="btn btn-p">修改模块首页内容</a> --%>
						<!-- <a href="javascript:void(0);" class="btn btn-p" id="recom">设置首页轮播</a>
						<a href="javascript:void(0);" class="btn btn-p" id="norecom">取消首页轮播</a>
						<a href="javascript:void(0);" class="btn btn-p" id="top">栏目头条</a>
						<a href="javascript:void(0);" class="btn btn-p" id="notop">取消栏目头条</a> -->
					</div>
				</div>
				<div class="check">
						<div class="check-item">
							<span class="check-tit">文章ID:</span>
							<input type="text" name="articleId" class="input mr10" value="${articleId}">
						</div>
						<div class="check-item">
							<span class="check-tit">标题:</span>
							<input type="text" name="title" class="input mr10" value="${title}">
						</div>
						<div class="check-item">
							<span class="check-tit">作者:</span>
							<input type="text" name="author" class="input mr10" value="${author}">
						</div>
						<div class="check-item date">
							<span class="check-tit">发布时间：</span>
							<input type="text" value="${beginDate}" class="input" name="beginDate" id="begindate" onClick="WdatePicker({maxDate:'#F{$dp.$D(\'enddate\')||\'%y-%M-%d\'}'})" readonly="readonly"/>
							<span class="check-tit">至</span>
							<input type="text" value="${endDate}" class="input" name="endDate" id="enddate" onClick="WdatePicker({minDate:'#F{$dp.$D(\'begindate\')}',maxDate:'%y-%M-%d'})" readonly="readonly"/>
						</div>
						<!-- <div class="clearfix"></div> -->
						<%-- <div class="check-item">
							<span class="check-tit">首页轮播:</span>
							<select class="input" name="isRecom" >
								<option value="0" <c:if test="${isRecom ==0}">selected="selected"</c:if> >否</option>
								<option value="1" <c:if test="${isRecom ==1}">selected="selected"</c:if> >是</option>
								<option value="" <c:if test="${empty isRecom}">selected="selected"</c:if>>全部</option>
							</select>
						</div> --%>
						<%-- <div class="check-item">
							<span class="check-tit">栏目头条:</span>
							<select class="input" name="isTop" >
								<option value="0" <c:if test="${isTop ==0}">selected="selected"</c:if> >否</option>
								<option value="1" <c:if test="${isTop ==1}">selected="selected"</c:if> >是</option>
								<option value="" <c:if test="${empty isTop}">selected="selected"</c:if>>全部</option>
							</select>
						</div> --%>
						<div class="check-item">
							<span class="check-tit">发布状态:</span>
							<select class="input" name="isPub" >
								<option value="0" <c:if test="${isPub ==0}">selected="selected"</c:if> >未发布</option>
								<option value="1" <c:if test="${isPub ==1}">selected="selected"</c:if> >已发布</option>
								<option value="" <c:if test="${empty isPub}">selected="selected"</c:if>>全部</option>
							</select>
						</div>
						<div class="check-btn">
							<input type="submit" class="btn w96" value="查  询">
						</div>
				</div>
				<div class="content">
					<table class="table" width="100%" border="0" cellspacing="0"
						cellpadding="0">
						<thead>
							<tr>
								<th width="20"><input type="checkbox" id="selectAll" onclick="selall();"/></th>
								<th>文章标题</th>
								<th>作者</th>
								<th>首页轮播</th>
								<th>栏目头条</th>
								<th>状态</th>
								<th>发布时间</th>
								<th>操作</th>
							</tr>
						</thead>
						<tbody>
							<c:forEach items="${page.datasource}" var="data">
							<tr>
								<td><input type="checkbox" name="checks" value="${data.articleId}"></td>
								<td>${data.title}</td>
								<td>${data.author}</td>
								<td>
									<c:if test="${data.isRecom ==1 }">是</c:if>
									<c:if test="${data.isRecom ==0 }">否</c:if>
								</td>
								<td>
									<c:if test="${data.isTop ==1 }">是</c:if>
									<c:if test="${data.isTop ==0 }">否</c:if>
								</td>
								<td>
									<c:if test="${data.isPub ==1 }"><span style="color:green;">已发布</span></c:if>
									<c:if test="${data.isPub ==0 }"><span style="color:gray;">未发布</span></c:if>
								</td>
								<td><fmt:formatDate value="${data.pubTime}" pattern="yyyy-MM-dd HH:mm:ss"/></td>
								<td>
									<a href="${pageContext.request.contextPath}/siteArticle/previewContent.html?articleId=${data.articleId}"
									id="${data.articleId}" target="_blank">预览</a>
									
									<a href="${pageContext.request.contextPath}/siteArticle/toUpdateArticle.html?articleId=${data.articleId}"
									id="${data.articleId}" >修改</a>
									<a href="javascript:;" id="${data.articleId}" class="remove">删除</a>
<!-- 									<a href="${pageContext.request.contextPath}/siteArticleComment/siteArticleCommentList.html?articleId=${data.articleId}" id="${data.articleId}" class="chaXiangqing">评论列表</a> -->
								</td>
							</tr>
							</c:forEach>
						</tbody>
					</table>
					<div id="page">
						<%@ include file="/v2/console/common/pageView.jsp"%>
					</div>
				</div>
			</form>
		</div>

		<div class="popBox remove-pop">
			<div class="popBox-back"></div>
			<div class="popBox-box">
				<div class="popBox-con">
					<div class="remove-con">
						<div class="tit">你确定要删除吗？</div>
						<div class="btns">
							<a href="javascript:;" class="btn w144">删 除</a> 
							<a href="javascript:;" class="btn-gray w144">取 消</a>
						</div>
					</div>
				</div>
			</div>
		</div>
	</div>
	<script type="text/javascript">
			$(function(){
				init();
				remove();// 
				quxiao();//
			});
		
			// 删除
			function remove(){
				$('.remove').click(function() {
					var id = this.id;
					$('.remove-pop').show();
					$('.remove-pop .btn').click(function(){
						$.ajax({
							type : "post",
							url : "${path}/siteArticle/delArticle.html",
							dataType : "json",
							data:{articleId:id},
							async : false,
							success : function(data) {
								if(data.ajax_status == "ajax_status_success"){
									$('.popBox').hide();
									 $("#pageForm").submit();
								}else{
									alert(data.msg);
								}
								return false;
							},
							error : function(XMLHttpRequest, textStatus, errorThrown){
					          alert("出错了！");
					       }
						});
					});
				});	
			}
			// 弹出框
			function quxiao(){
				var $btn = $('.popBox').find('.btn-gray');
				$btn.click(function() {
					$('.popBox').hide();
				});
			}
		
			//全选框
			function selall(){
				var isChecked = $("#selectAll")[0].checked;
				$(".table").find("tbody").find("input[type='checkbox']").each(function(){
						this.checked = isChecked;
				});
			}
			
			
			function init(){
				$(".table").find("tbody").find("input[type='checkbox']").click(function(){
					if(this.checked){
						if($(".table").find("tbody").find('input:checked').size() == $(".table").find("tbody").find("input[type='checkbox']").size()){
							$("#selectAll")[0].checked = true;
						}
					}else{
						$("#selectAll")[0].checked = false;
					}
				});
				
				$("#pub").click(function(){
					pub(1);
				});
				
				$("#nopub").click(function(){
					pub(0);
				});
				
				$("#recom").click(function(){
					setValue("isRecom",1);
				});
				
				$("#norecom").click(function(){
					setValue("isRecom",0);
				});
				
				$("#top").click(function(){
					setValue("isTop",1);
				});
				
				$("#notop").click(function(){
					setValue("isTop",0);
				});
			}
			
			function getcheckids(){
				var ids = "";
			      $('input:checkbox[name=checks]:checked').each(function(i){
			       if(0==i){
			    	   ids = $(this).val();
			       }else{
			    	   ids += (","+$(this).val());
			       }
			      });
			      if(ids.length <= 0){
			    	  alert("请选择至少一篇文章");
			    	  return;
			      }
			     return ids;
			} 
			
			function pub(v){
				var articleids = getcheckids();
				$.ajax({
					type : "post",
					url : "${path}/siteArticle/pubArticle.html",
					dataType : "json",
					data:{ids:articleids,status:v},
					async : false,
					success : function(data) {
						if(data.ajax_status == "ajax_status_success"){
							 $("#pageForm").submit();
						}else{
							alert(data.msg);
						}
						return false;
					},
					error : function(XMLHttpRequest, textStatus, errorThrown){
			          alert("出错了！");
			       }
				});
			}
			
			function setValue(fname,v){
				var articleids = getcheckids();
				$.ajax({
					type : "post",
					url : "${path}/siteArticle/setValue.html",
					dataType : "json",
					data:{ids:articleids,name:fname,value:v},
					async : false,
					success : function(data) {
						if(data.ajax_status == "ajax_status_success"){
							 $("#pageForm").submit();
						}else{
							alert(data.msg);
						}
						return false;
					},
					error : function(XMLHttpRequest, textStatus, errorThrown){
			          alert("出错了！");
			       }
				});
			}
	</script>
</body>
</html>